%
% Start preamble
%
%
% The very first thing in a latex document is the document class
%
% other relevant classes are 
\documentclass[twoside,a4paper,11pt]{scrreprt}
%
%
%************************************************
% packages
%************************************************
% You do not need all of these packages
% Some of them are quite nice though
\usepackage[norsk]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}	% graphics handling
\usepackage{eso-pic} % for setting coverpage background
\usepackage{mathpazo}
\usepackage{varioref}
\usepackage{listings}	% listing source code
\usepackage{color}	% include colors
\usepackage{verbatim}	% including verbatim text
\usepackage{a4wide}	% a4 page with smaller margins
\usepackage{caption}	% adds options for captions
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{units}	% typesetting units
\usepackage{bm}		% bold text in math mode
\usepackage{longtable}	% allow tables spanning more than one page
\usepackage{array}	% array package
\usepackage{cleveref}	% clever referencing, use \cref instead of \ref
\usepackage{colortbl}	% adds color to latex tables
\usepackage{multirow}	% multirows in arrays
\usepackage[round]{natbib}
\usepackage{psfrag}
\usepackage{mdwlist}
\usepackage{url}	% url formatting
\usepackage{ulem}
\usepackage{appendix}	% appendix package
\usepackage{hyperref}	% include hyperrefs for urls

% Defining a new counter to enumerate the examples
\newcounter{num}
\setcounter{num}{1}

%-------------------------------------
% new commands
%-------------------------------------
\newcommand{\num}{\thenum \stepcounter{num}}   % prints the value of num and adds 1
\newcommand{\tbf}[1]{\textbf{\textit{#1}}}	% puts text in italics and bold
%
\newcommand{\bi}{\textbf{\textit{i}}}		% quick way of writing unit vectors
\newcommand{\bj}{\textbf{\textit{j}}}
\newcommand{\bk}{\textbf{\textit{k}}}
%
% quick ways of writing differentials
\newcommand{\tdiff}[2]{\ensuremath{\frac{d#2}{d{#1}}}}
\newcommand{\tdifforder}[3]{\ensuremath{\frac{d^{#2}#3}{d{#1}^{#2}}}}
\newcommand{\pdiff}[2]{\ensuremath{\frac{\partial#2 }{\partial#1}}}
\newcommand{\pdifforder}[3]{\ensuremath{\frac{\partial^{#2}#3}{\partial{#1}^{#2}}}}
\newcommand{\mpdiff}[3]{\ensuremath{\frac{\partial^{2}#3}{\partial{#1}\partial{#2}}}}
%
% sets the enumerator to a) b) c)
\renewcommand{\labelenumi}{\alph{enumi})}
%
% quick way of writing double ant trible integrals
\newcommand{\dbint}{\int\!\!\!\int}
\newcommand{\trint}{\int\!\!\!\int\!\!\!\int}
%
\newcommand{\duline}[1]{\underline{\underline{#1}}}  % two lines under the answer
%-------------------------------------
% formatting
%-------------------------------------
\hyphenpenalty=5000 % increase latex's penalty for splitting words
\tolerance=1000 % increase latex's tolerance for spacing
%-------------------------------------
% paths
%-------------------------------------
\graphicspath{{figs/}}
%-------------------------------------
% Title page (if you want one)
%-------------------------------------
\title{Title goes here\\
\author{Your name}
Seminar}
\date{Month year}
%
%
% End preamble
%
%-------------------------------------
% Beginning of document
%-------------------------------------
\begin{document}

% Create the title page
\maketitle

%-------------------------------------
% Writing equations
%-------------------------------------
\chapter{Writing equations in \LaTeX}

%-------------------------------------
% Simple examples
%-------------------------------------
\section*{\underline{Simple examples}}

%******************************
    \subsection*{Example \num}
    Use \texttt{equation} for numbered equations
    \begin{equation}
        f(x,y,z) = 3x-5y+2z
        \label{eq:f}
    \end{equation}
%
%******************************
    \subsection*{Example \num}
    Text in equations

    \[
        x^2+y^2+2z^2 = 4 \;\mbox{ and }\; z = e^{x-y}
    \]
%
%******************************
    \subsection*{Example \num}
    Use \texttt{eqnarray} for aligned equations
    (numbering is suppressed by adding $\ast$)

    \begin{eqnarray*}
        F(x,y,z) & = & x^2+y^2+2z^2 = 4 \\
        G(x,y,z) & = & e^{x-y}-z = 0
    \end{eqnarray*}
%
%******************************
    \subsection*{Example \num}
    Differentials
    \[
        \frac{ \partial y } { \partial x}
    \]
%
%******************************
    \subsection*{Example \num}
    Differentials (using predefined macros)
    \[u=F(s,t) = f(X(s,t),Y(s,t))\]
    \[
        \pdiff{s}{F} = \pdiff{x}{f}\pdiff{s}{X}+\pdiff{y}{f}\pdiff{s}{Y}
    \]
%
%******************************
    \subsection*{Example \num}
    Vector functions
    \[
        \tbf{f}(x,y)=e^{x+2y}\bi + \sin(y+2x)\bj = f_1\bi+f_2\bj,
    \]
%
%-------------------------------------
% Simple examples
%-------------------------------------
\section*{\underline{Advanced examples}}
%
%******************************
    \subsection*{Example \num}
    The Jacobi matrix of a vector function

    \[\tbf{f}(x_1,x_2,\cdots,x_n) = (f_1(x_1,\cdots,x_n),\cdots,f_m(x_1,\cdots,x_n)):\]

    \begin{center}
	    \begin{math} D\tbf{f}(\tbf{a})  = \left(
            \begin{array}{ccccc}

                    D_1f_1(\tbf{a})  & D_2f_1(\tbf{a}) & \cdots & D_nf_1(\tbf{a}) \\
                    D_1 f_2(\tbf{a}) &                 &        & \vdots          \\
                    \vdots           &                 & \ddots &                 \\
                    D_1f_m(\tbf{a})  & \cdots          &        & D_nf_m(\tbf{a})

            \end{array} \right)
        \end{math}
    \end{center}
%
%******************************
    \subsection*{Example \num}
    Advanced integrals
    \[
        V = \mathop{\trint}_V\,dxdydz = \mathop{\trint}_{V'} |-\rho^2\sin\phi|\,d\rho d\theta d\phi
    \]
    \begin{equation}
        \left. \begin{array}{lcl}
                    0  \leq & \rho & \leq  a \\
                    0  \leq & \phi & \leq  \pi/4 \\
                    0 \leq & \theta & \leq 2\pi
                \end{array} \right\} V' \nonumber
    \end{equation}
    \begin{eqnarray*}
        V & = & 2\pi\int_0^{\pi/4}\sin\phi\left(\int_0^a \rho^2\,d\rho\right) d\phi \\
        & = & 2\pi\frac{a^3}{3}\int_0^{\pi/4}\sin\phi\,d\phi \\
        & = & \duline{\frac{2\pi a^3}{3}\left(1-\frac{1}{\sqrt{2}}\right)}
    \end{eqnarray*}
%
%******************************
    \subsection*{Example \num}
    Stokes' theorem
    \[
        \int_C \tbf{f}\cdot d\bm{\alpha}  =  \mathop{\dbint}_S (\nabla\times\tbf{f})\cdot\tbf{n}\,dS
    \]
    \[
         =  \mathop{\dbint}_T (\nabla\times\tbf{f})\cdot\underbrace{\frac{\pdiff{\theta}{\tbf{r}}\times\pdiff{z}{\tbf{r}}}{\left\|\pdiff{\theta}{\tbf{r}}\times\pdiff{z}{\tbf{r}}\right\|}}_{\tbf{n}}\underbrace{\left\|\pdiff{\theta}{\tbf{r}}\times\pdiff{z}{\tbf{r}}\right\|\,d\theta dz}_{dS}
    \]
    \begin{equation}
        \pdiff{\theta}{\tbf{r}}\times\pdiff{z}{\tbf{r}} = \left|
            \begin{array}{ccc}
                    \bi            & \bj           & \bk \\
                    -r_0\sin\theta & r_0\cos\theta & 0   \\
                    0              & 0             & 1
            \end{array} \right| = r_0\cos\theta\bi+r_0\sin\theta\bj \nonumber
    \end{equation}



\end{document}
